package a_create;

class ThreadDemo extends Thread {
    public void run() {
        System.out.println("ThreadDemo.run执行");
        for (int i = 0; i < 10; i++) {
            System.out.println("ThreadDemo执行：" + i);
        }
        System.out.println("ThreadDemo.run结束");
    }
}

class RunnableDemo implements Runnable {
    @Override
    public void run() {
        System.out.println("RunnableDemo.run执行");
        for (int i = 0; i < 10; i++) {
            System.out.println("RunnableDemo执行：" + i);
        }
        System.out.println("RunnableDemo.run结束");
    }
}

public class CreateDemo {
    public static void main(String[] args) {
        //创建方法一 继承类Thread
        ThreadDemo td = new ThreadDemo();
        //注：如果直接调用run方法，则是主线程执行对象的方法，不是新建的线程
        td.start();
        //创建方法二 继承Runnable接口
        Thread t = new Thread(new RunnableDemo());
        t.start();
    }

}
